package goodroommate.service.impl;

import java.util.LinkedList;

import goodroommate.dal.DatabaseSession;
import goodroommate.dao.ICommentDao;
import goodroommate.dao.impl.CommentDao;
import goodroommate.domain.Comment;
import goodroommate.exception.DatabaseException;
import goodroommate.exception.ItemNotExistsException;
import goodroommate.service.ICommentService;

public class CommentService implements ICommentService {
	ICommentDao commentDao=new CommentDao();
	@Override
	public void addComment(long commentator, long reply, int postingid, String content) throws DatabaseException {
		
		try(DatabaseSession dbs=new DatabaseSession()){
			Comment comment=new Comment();
			comment.setCommentator(commentator);
			comment.setReply(reply);
			comment.setPostingid(postingid);
			comment.setContent(content);
			commentDao.addComment(dbs, comment);
		}
	}
	@Override
	public LinkedList<Comment> getCommentByPostingID(int postingid) throws DatabaseException, ItemNotExistsException {
		
		LinkedList<Comment> comments=null;
		try(DatabaseSession dbs=new DatabaseSession()){
			
			comments=commentDao.getCommentByPostingID(dbs, postingid);
			if (comments.size() == 0)
				throw new ItemNotExistsException();
			return comments;
			
		}
	}
	
	

}
